home *** CD-ROM | disk | FTP | other *** search
/ ADA Programming Guide / ADA Programming Guide.iso / ada_gnu / adainc / s-valenu.adb < prev    next >
Text File  |  1996-01-30  |  3KB  |  65 lines

  1. ------------------------------------------------------------------------------
  2. --                                                                          --
  3. --                         GNAT COMPILER COMPONENTS                         --
  4. --                                                                          --
  5. --                      S Y S T E M . V A L _ E N U M                       --
  6. --                                                                          --
  7. --                                 B o d y                                  --
  8. --                                                                          --
  9. --                            $Revision: 1.6 $                              --
  10. --                                                                          --
  11. --           Copyright (c) 1992,1993,1994 NYU, All Rights Reserved          --
  12. --                                                                          --
  13. -- The GNAT library is free software; you can redistribute it and/or modify --
  14. -- it under terms of the GNU Library General Public License as published by --
  15. -- the Free Software  Foundation; either version 2, or (at your option) any --
  16. -- later version.  The GNAT library is distributed in the hope that it will --
  17. -- be useful, but WITHOUT ANY WARRANTY;  without even  the implied warranty --
  18. -- of MERCHANTABILITY  or  FITNESS FOR  A PARTICULAR PURPOSE.  See the  GNU --
  19. -- Library  General  Public  License for  more  details.  You  should  have --
  20. -- received  a copy of the GNU  Library  General Public License  along with --
  21. -- the GNAT library;  see the file  COPYING.LIB.  If not, write to the Free --
  22. -- Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.        --
  23. --                                                                          --
  24. ------------------------------------------------------------------------------
  25.  
  26. with System.Val_Util; use System.Val_Util;
  27. with Unchecked_Conversion;
  28.  
  29. package body System.Val_Enum is
  30.  
  31.    -----------------------
  32.    -- Value_Enumeration --
  33.    -----------------------
  34.  
  35.    function Value_Enumeration
  36.      (A        : Address;
  37.       Last_Pos : Natural;
  38.       Str      : String)
  39.       return     Natural
  40.    is
  41.       type String_Access is access String;
  42.       type Enum_Table is array (Natural) of String_Access;
  43.       type Enum_Table_Ptr is access Enum_Table;
  44.       function A_To_T is new Unchecked_Conversion (Address, Enum_Table_Ptr);
  45.  
  46.       F : Natural;
  47.       L : Natural;
  48.       S : String (Str'Range) := Str;
  49.       T : constant Enum_Table_Ptr := A_To_T (A);
  50.  
  51.    begin
  52.       Normalize_String (S, F, L);
  53.  
  54.       for J in 0 .. Last_Pos loop
  55.          if T (J).all = S (F .. L) then
  56.             return J;
  57.          end if;
  58.       end loop;
  59.  
  60.       raise Constraint_Error;
  61.  
  62.    end Value_Enumeration;
  63.  
  64. end System.Val_Enum;
  65.